<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 帮助中心 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->

<template>
	<view class="container" v-if="loadEnd">
		<view class="container-list" v-if="helpList.length">
			<view class="list-item flex align-items-center" v-for="(item, index) in helpList" :key="index" @click="toDetails(item.id)">
				<view class="item-text flex-item">{{item.title}}</view>
				<image class="item-icon" src="/static/arrow_right.png" mode="aspectFit"></image>
				<view class="item-mask" v-if="helpLoading">
					<view class="mask-box"></view>
				</view>
			</view>
		</view>
		<empty top="30%" title="暂无相关内容~" v-else></empty>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data() {
			return {
				// 加载完成
				loadEnd: false,
				// 分类查询参数
				page: 1,
				limit: 20,
				hasMore: false,
				// 帮助列表
				helpList: [],
				// 帮助列表是否加载
				helpLoading: false,
			}
		},
		computed: {
			...mapState({
				shareTitle: state => state.shareTitle,
				shareImage: state => state.shareImage,
			})
		},
		onLoad() {
			uni.showLoading({
				title: "加载中"
			})
			this.getHelpList(() => {
				uni.hideLoading()
				this.loadEnd = true
			})
		},
		onPullDownRefresh() {
			this.page = 1
			this.helpLoading = true
			this.getHelpList(() => {
				this.helpLoading = false
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			if (this.hasMore) {
				this.page++
				this.getHelpList()
			}
		},
		onShareAppMessage() {
			return {
				title: this.shareTitle,
				imageUrl: this.shareImage,
			}
		},
		onShareTimeline() {
			return {
				title: this.shareTitle,
				imageUrl: this.shareImage,
			}
		},
		methods: {
			// 获取帮助中心列表
			getHelpList(fn) {
				this.$util.request("main.help.list", {
					page: this.page,
					limit: this.limit,
				}).then(res => {
					if (fn) fn()
					if (res.code == 1) {
						let list = res.data.data
						this.hasMore = this.page < res.data.total / this.limit ? true : false
						this.helpList = this.page == 1 ? list : [...this.helpList, ...list];
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					if (fn) fn()
					console.error('获取帮助中心列表 ', error)
				})
			},
			// 跳转详情页面
			toDetails(id) {
				this.$util.toPage({
					mode: 1,
					path: "/pages/passenger/mine/help/details?id=" + id
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 32rpx;

		.container-list {
			.list-item {
				position: relative;
				margin-top: 32rpx;
				border-radius: 32rpx;
				overflow: hidden;
				background: #FFF;
				padding: 36rpx 32rpx;

				&:first-child {
					margin-top: 0;
				}

				.item-text {
					color: #242629;
					font-size: 28rpx;
					line-height: 40rpx;
				}

				.item-icon {
					margin-left: 24rpx;
					width: 32rpx;
					height: 32rpx;
				}

				.item-mask {
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					z-index: 9;
					background: #FFF;
					padding: 32rpx;

					.mask-box {
						width: 100%;
						height: 100%;
						background: #eee;
					}
				}
			}
		}
	}
</style>